<template>
	<view class="content">
		<view class="box" v-if="isScanCode">
			<view class="pay-loading" v-if="loading">
				<image src="https://www.sdxiecheng.cn/img/loading.gif" mode="heightFix"></image>
				<view class="pay-des">
					<view class="name">支付成功</view>
					<view class="des">
						正在打开柜门，请耐心等待
					</view>
				</view>
			</view>
			<view class="pay-s" v-else>
				<view class="name">
					{{num}}号柜门已打开
				</view>
				<view class="des">
					{{ orderInfo.name }}
				</view>
				
				<image src="https://www.sdxiecheng.cn/img/wancheng.png" mode=""></image>
				<view class="pay-btn">
					<button class="u-reset-button btn1" @click="shouye">返回首页</button>
					<button class="u-reset-button btn2" @click="seeOrder(2)">查看订单</button>
				</view>
			</view>
		</view>
		<view class="box" v-else>
			<view class="pay-s">
				<view class="name">
					支付成功
					<!-- {{ orderInfo.name }} -->
				</view>
			<!-- 	<view class="des">
					地址：{{ orderInfo.address }}
				</view> -->
				
				<image src="https://www.sdxiecheng.cn/img/wancheng.png" mode=""></image>
				<view class="pay-btn">
					<button class="u-reset-button btn1" @click="shouye">返回首页</button>
					<button class="u-reset-button btn2" @click="seeOrder(1)">查看订单</button>
				</view>
			</view>
		</view>
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading:true,
				isScanCode:false,
				order_id:'',
				orderInfo:{},
				num:0,
				detail_id:0
			}
		},
		onLoad(e) {
			let that = this
			that.isScanCode = that.$store.state.isScanCode
			that.order_id = e.order_id
			that.detail_id = e.detail_id
			console.log('支付成功->',e)
			this.getDcxOrder()
			// setTimeout(() =>{
			// 	that.loading = false
			// },1500)
		},
		methods: {
			shouye(){
				uni.switchTab({
					url:'../index/index'
				})
			},
			seeOrder(index){
				uni.setStorageSync('index',index)
				uni.$emit('updateOrder',{index:index})
				uni.navigateTo({
					url:'../order/all_city_order'
				})
				// uni.reLaunch({
				// 	url:'../order/details/details?id='+this.order_id+'&type=dcx'
				// })
			},
			// 获取订单详情
			getDcxOrder(){
				uni.$u.http.post('/order/orderdetail',{
					order_id:this.order_id
				}).then(res =>{
					console.log(res)
					this.orderInfo = res.data
					if(this.isScanCode){
						this.openGuiMen()
					}
				})
			},
			// 打开柜门
			openGuiMen(){
				let that = this
				uni.$u.http.post('/device/open_cshoes',{
					id:this.$store.state.shoecabinet_id,
					order_id:this.detail_id
				}).then(res =>{
					// // that.guiziChengGongShow = true
					// that.num = res.data.info
					// that.loading = false
					// uni.hideLoading()
					// console.log(res)
					
					if (res.code == 200) {
						that.num = res.data.info
						uni.hideLoading()
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				}).catch(err =>{
					console.log(err)
					uni.showToast({
						icon:'none',
						title:err.data.msg
					})
				})
			}
		}
	}
</script>

<style lang="less">
	.content{
		padding:  10rpx 20rpx;
	}
	.box{
		width: 100%;
		height: 100%;
		background: #FFFFFF;
		height: calc(100vh - 20rpx );
		border-radius: 10rpx ;
		overflow: hidden;
	}
// 等待
.pay-loading{
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;
	image{
		// width: 242rpx;
		// height: 240rpx;
	}
	.pay-des{
		margin-top: -70rpx;
		.name{
			font-size: 48rpx;
			margin-bottom: 14rpx;
			text-align:center;
		}
		.des{
			font-size: 26rpx;
			text-align:center;
			color: #7C7C7C;
		}
	}
}
// 支付成功
.pay-s{
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;
	padding-top: 99rpx;
	image{
		width: 152rpx;
		height: 152rpx;
		margin-bottom: 80rpx;
	}
	.name{
		font-size: 48rpx;
		margin-bottom: 50rpx;
		line-height: 1;
	}
	.des{
		font-size: 26rpx;
		color: #7C7C7C;
		line-height: 1;
		margin-bottom: 94rpx;
	}
	.pay-btn{
		display: flex;
		align-items: center;
		button{
			width: 210rpx;
			height: 70rpx;
			text-align: center;
			line-height: 70rpx;
			border-radius: 35rpx;
			font-size: 32rpx;
			color: #FFFFFF;
			margin: 0;
		}
		.btn1{
			background: #ECBC2B;
			margin-right: 46rpx;
		}
		.btn2{
			background: #FF9A33;
		}
	}
}
</style>
